<template>
  <div class="swiper-wrap">
    <swiper :options="swiperOption" ref="mySwiper" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl">
      </swiper-slide>
      <!-- Optional controls -->
      <!-- 去掉轮播组件中无用的东西 -->
      <div class="swiper-pagination" slot="pagination"></div>
      <!-- <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
      <div class="swiper-scrollbar" slot="scrollbar"></div>-->
    </swiper>
  </div>
</template>

<script>
export default {
  name: "HomeSwiper",
  props:{
    list:Array
  },
  data() {
    return {
      swiperOption: {
        pagination: ".swiper-pagination",
        loop: true,
        autoplay: 3000,
        speed:1000,
        // autoplayDisableOnInteraction 此项设置为false之后轮播点击之后会继续轮播不会停止
        autoplayDisableOnInteraction: false
      },
      swiperList: [
        {
          id: "0001",
          imgUrl:
            "http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20192/b0b0fe379b48eb4bfa6dab00de7d209f.jpg_750x200_6a1a39da.jpg"
        },
        {
          id: "0002",
          imgUrl:
            "http://mp-piao-admincp.qunarzz.com/mp_piao_admin_mp_piao_admin/admin/20193/87a224d0349d94a11e97f31aa1aba4f5.jpg_750x200_1f78af87.jpg"
        }
      ]
    };
  },
  computed:{
    showSwiper(){
      return this.list.length
    }
  }
};
</script>


<style lang="stylus" scoped>
// 由于.swiper-pagination-bullet-active 是在swiper组件中而scoped限制了其修改所以就用到一个 样式穿透 就不受scoped的限制
.swiper-wrap >>> .swiper-pagination-bullet-active {
  background: #fff;
}

.swiper-wrap {
  // touch-action: none;
  // 解决波动开始加载时候防止排版的波动
  width: 100%;
  height: 0;
  padding-bottom: 31.25%;
  overflow: hidden;

  .swiper-img {
    width: 100%;
  }
}
</style>
